var express = require("express")
const mongoose = require("mongoose")

var app = express()
const bodyParser = require('body-parser')
const passport = require('passport')
const db = require('./config/keys').mongoURI
var str = ""

// 引入api:
const Users = require('./routers/api/users')
const Profiels = require('./routers/api/profiles')

// app.use(bodyParser())
app.use(bodyParser.json({ type: 'application/*+json' }))
app.use(bodyParser.urlencoded({extended:false}))

app.use(bodyParser.raw({ type: 'application/vnd.custom-type' }))

app.use(bodyParser.text({ type: 'text/html' }))

// app.use(function (req, res) {
//     console.log("------------------ "+JSON.stringify(req.body, null, 2))
//     res.setHeader('Content-Type', 'text/plain')
//     res.write('you posted:\n')
//     res.end(JSON.stringify(req.body, null, 2))
//   })


mongoose.connect(db,{useNewUrlParser:true})
        .then(() => console.log("Mongo lian shang la !"))
        .catch(err => console.log(err))


// 引用路径
app.use('/api/users',Users)
app.use('/api/profiles',Profiels)

app.use(passport.initialize())
// 引用并传递 passport到
require('./config/passport')(passport)
const port = process.port || 3000


// app.get("/",(req,res) => {
//     res.send(str)
// })

app.listen(port,()=> {
    console.log("mongoose connected ")
})

